local gamelib = require "club.threecard.gamelib"
local slotlib = require "club.threecard.slotlib"
local components = slotlib.require "components"

local slot_system = slotlib.systems.slot_system
local class = gamelib.entitas.class
local Matcher = gamelib.entitas.Matcher
local GroupEvent = gamelib.entitas.GroupEvent

local delay_system = class("delay_system", slot_system)

function delay_system:initialize()
    self.context.machine:replace(components.delay_component, 1);
end

function delay_system:get_trigger()
    return {{Matcher({components.delay_component}), GroupEvent.ADDED | GroupEvent.UPDATE}};
end

function delay_system:filter(entity)
    return entity:has(components.delay_component)
end

function delay_system:execute(entitas)
    if entitas:size() ~= 1 then
        gamelib.log.error("数据错误，结果组件不可能~=1->"..entitas:size())
        return;
    end

    local data = self.context.machine:get(components.delay_component);
    if data then
        self:wait(data.time);
    end
end

return delay_system